﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace PropertyManagement {
    public static class Helper {
        private static readonly Regex phoneNumberReg = new Regex(@"^(1(([35][0-9])|(47)|[8][01236789]))\d{8}$",
                                                                 RegexOptions.Compiled);

        private static readonly Regex phoneNumberReg2 = new Regex(@"^0\d{2,3}(\-)?\d{7,8}$",
                                                                 RegexOptions.Compiled);

        private static readonly Regex IdentityCardReg = new Regex(@"^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$",RegexOptions.Compiled);

        public static bool ValidatePhoneNumber(string value) {
            return phoneNumberReg.IsMatch(value) || phoneNumberReg2.IsMatch(value);
           
        }

        public static bool ValidateIdentityCard(string value) {
            return IdentityCardReg.IsMatch(value);
        }

        public static int GetInt(string str) {
            if (!string.IsNullOrEmpty(str)) {
                int output = 1;
                if (int.TryParse(str, out output)) {
                    return output;
                }
            }
            return 0;
        }
    }
}
